package com.gopay.common.cps.dao.fund.impl;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.cps.dao.fund.FundCpsMainDao;
import com.gopay.common.cps.dao.fund.FundCpsOrderDao;
import com.gopay.common.domain.cps.CpsGenMainOrder;
import com.gopay.common.domain.cps.CpsGenPayOrder;
import com.gopay.common.domain.fund.FundGopayCpsGenOrder;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.*;
/**
 * @BindCardDAOImpl.java
 * @author baiyunpeng
 * @2016年7月4日 上午10:27:00  www.gopay.com.cn Inc.All rights reserved.
 */
@Repository("fundCpsOrderDao")
public class FundCpsOrderDaoImpl extends BaseDAOImpl<FundGopayCpsGenOrder,String> implements FundCpsOrderDao {
    protected Logger logger = Logger.getLogger(getClass());
    @Resource(name = "fundCpsMainDaoExt")
    private FundCpsMainDao fundCpsMainDao;

    @Override
    public FundGopayCpsGenOrder getFundOrderRemaker2ByGopayId(String gopayOrderId) {
        if (gopayOrderId != null) {
            StringBuffer sql = new StringBuffer("");
            sql.append("from FundGopayCpsGenOrder where gopayOrderId=:gopayOrderId");
            Map<String, Object> map = new HashMap<>();
            map.put("gopayOrderId", gopayOrderId);
            List<FundGopayCpsGenOrder> byHql = findByHql(sql.toString(), map);
            if (byHql != null && byHql.size() > 0) {
                return byHql.get(0);
            }
        }
        return null;
    }

    @Override
    public FundGopayCpsGenOrder getFundGopayOrder(String gopayOrderId) {
        if (StringUtils.isNotBlank(gopayOrderId)) {
            StringBuffer sql = new StringBuffer("from FundGopayCpsGenOrder where gopayOrderId=:gopayOrderId");
            Map<String, Object> map = new HashMap<>();
            map.put("gopayOrderId", gopayOrderId);
            List<FundGopayCpsGenOrder> byHql = findByHql(sql.toString(), map);
            if (byHql.size() > 0) {
                return byHql.get(0);
            }
        }
        return null;
    }

    @Override
    public List<FundGopayCpsGenOrder> getFundOrderByRemaker2(String remark2) {
        if (remark2 != null) {
            StringBuffer sql = new StringBuffer("");
            sql.append("from FundGopayCpsGenOrder  where merRemark2=:merRemark2");
            Map<String, Object> map = new HashMap<>();
            map.put("merRemark2", remark2);
            logger.error("remaker2.................." + remark2);
            List<FundGopayCpsGenOrder> byHql = findByHql(sql.toString(), map);
            logger.error("sql.................." + sql.toString() + "......\r\n...........集合" + byHql);
            return byHql;
        }
        return null;
    }

    @Override
    public FundGopayCpsGenOrder getFundOrderByReleveGopayId(String releveGopayId) {
        if (releveGopayId != null) {

            StringBuffer sql = new StringBuffer("");
            sql.append("from FundGopayCpsGenOrder where gopayOrderId=:releveGopayId");
            Map<String, Object> map = new HashMap<>();
            map.put("releveGopayId", releveGopayId);
            List<FundGopayCpsGenOrder> byHql = findByHql(sql.toString(), map);
            if (byHql != null && byHql.size() > 0) {
                return byHql.get(0);
            }
        }
        return null;
    }

    /**
     * 批量插入Fund主订单记录
     *
     * @param connection
     * @param orderList
     * @throws SQLException
     */
    @Override
    public void batchInsertMainOrders(Connection connection, final List<FundGopayCpsGenOrder> orderList) throws SQLException {
        // 插入sql
        StringBuffer sql = new StringBuffer("insert into FUND_GOPAY_CPS_GEN_ORDER (");
        StringBuffer values = new StringBuffer("");

        sql.append("GOPAY_ORDER_ID,");
        values.append("?,");
        sql.append("AGENT_SIGN_NO,");
        values.append("?,");
        sql.append("TRANS_DTL_SEQ,");
        values.append("?,");
        sql.append("FUND_NO,");
        values.append("?,");
        sql.append("GOPAY_INT_TXN_CD,");
        values.append("?,");
        sql.append("MERCHANT_ID,");
        values.append("?,");
        sql.append("MER_ORDER_NUM,");
        values.append("?,");
        sql.append("TRAN_TYPE,");
        values.append("?,");
        sql.append("ORDER_TYPE,");
        values.append("?,");
        sql.append("TOTAL_ORDER_AMT,");
        values.append("?,");
        sql.append("TOTAL_ORDER_FEE_AMT,");
        values.append("?,");
        sql.append("ORDER_DEAL_AMT,");
        values.append("?,");
        sql.append("ORDER_REAL_FEE_AMT,");
        values.append("?,");
        sql.append("TRAN_FINISH_TIME,");
        values.append("?,");
        sql.append("ORIG_MER_ORDER_NUM,");
        values.append("?,");
        sql.append("RESP_CODE,");
        values.append("?,");
        sql.append("VERIFY_CODE,");
        values.append("?,");
        sql.append("CARD_NO,");
        values.append("?,");
        sql.append("BANK_CODE,");
        values.append("?,");
        sql.append("STLM_DATE,");
        values.append("?,");
        sql.append("BACKGROUND_MER_URL,");
        values.append("?,");
        sql.append("MER_REMARK1,");
        values.append("?,");
        sql.append("MER_REMARK2,");
        values.append("?,");
        sql.append("TRAN_IP,");
        values.append("?,");
        sql.append("DATA_SOURCE,");
        values.append("?,");
        sql.append("SOURCE,");
        values.append("?,");
        sql.append("MEMO,");
        values.append("?,");
        sql.append("CREATED_TS,");
        values.append("?,");
        sql.append("LAST_UPD_TS,");
        values.append("?,");
        sql.append("MER_TXN_TM,");
        values.append("?,");
        sql.append("MER_TXN_AMT,");
        values.append("?,");
        sql.append("VERSION,");
        values.append("?,");//
        sql.append("KEY_ID");
        values.append("?");
        sql.append(" ) values ( ");
        sql.append(values);
        sql.append(" ) ");

        PreparedStatement pst = connection.prepareStatement(sql.toString());

        FundGopayCpsGenOrder order = null;
//        Date now = new Date(System.currentTimeMillis());
        for (int i = 0; i < orderList.size(); i++) {
            order = orderList.get(i);

            //GOPAY_ORDER_ID
            pst.setString(1, order.getGopayOrderId());

            //AgentSignNo
            pst.setString(2, order.getAgentSignNo());

            //TransDtlSeq
            pst.setInt(3, order.getTransDtlSeq());

            //FUND_NO
            pst.setString(4, order.getFundNo());

            //GOPAY_INT_TXN_CD
            pst.setString(5, order.getGopayIntTxnCd());

            //MERCHANT_ID
            pst.setString(6, order.getMerchantId());

            //MER_ORDER_NUM
            pst.setString(7, order.getMerOrderNum());

            //TRAN_TYPE
            pst.setString(8, order.getTranType());

            //ORDER_TYPE
            pst.setString(9, order.getOrderType());

            //TOTAL_ORDER_AMT
            pst.setBigDecimal(10, order.getTotalOrderAmt());

            //TOTAL_ORDER_FEE_AMT
            pst.setBigDecimal(11, order.getTotalOrderFeeAmt());

            //ORDER_DEAL_AMT
            pst.setBigDecimal(12, order.getOrderDealAmt());

            //ORDER_REAL_FEE_AMT
            pst.setBigDecimal(13, order.getOrderRealFeeAmt());

            //TRAN_FINISH_TIME
            Date tranFinishTime = order.getTranFinishTime();
            if (tranFinishTime != null) {
                pst.setTimestamp(14, new Timestamp(tranFinishTime.getTime()));
            } else {
                pst.setTimestamp(14, null);
            }
            //ORIG_MER_ORDER_NUM
            pst.setString(15, order.getOrigMerOrderNum());

            //RESP_CODE
            pst.setString(16, order.getRespCode());

            //VERIFY_CODE
            pst.setString(17, order.getVerifyCode());

            //CARD_NO
            pst.setString(18, order.getCardNo());

            //BANK_CODE
            pst.setString(19, order.getBankCode());

            Date stlmDate = order.getStlmDate();
            if (stlmDate != null) {
                pst.setTimestamp(20, new Timestamp(stlmDate.getTime()));
            } else {
                pst.setTimestamp(20, null);
            }
            //STLM_DATE
            //BACKGROUND_MER_URL
            pst.setString(21, order.getBackgroundMerUrl());

            //MER_REMARK1
            pst.setString(22, order.getMerRemark1());

            //MER_REMARK2
            pst.setString(23, order.getMerRemark2());

            //TRAN_IP
            pst.setString(24, order.getTranIp());

            //DATA_SOURCE
            pst.setString(25, order.getDataSource());

            //SOURCE
            pst.setString(26, order.getSource());

            //MEMO
            pst.setString(27, order.getMemo());

            //CREATED_TS
            pst.setTimestamp(28, new Timestamp(order.getCreatedTs().getTime()));
            //pst.setTimestamp(6, new Timestamp(order.getMerTxnTm().getTime()));

            //LAST_UPD_TS
            pst.setTimestamp(29, new Timestamp(order.getLastUpdTs().getTime()));
            //VERSION
            //MER_TXN_TM
            pst.setTimestamp(30, new Timestamp(order.getMerTxnTm().getTime()));
            pst.setBigDecimal(31, order.getMerTxnAmt());
            pst.setInt(32, order.getVersion());
            pst.setString(33, order.getKeyId());
            // 把一个SQL命令加入命令列表
            pst.addBatch();
        }

        // 执行批量插入
        pst.executeBatch();
    }

    /**
     * 通用方法:
     * 批量更新从订单状态
     *
     * @param maps
     * @return
     */
    @Override
    public Integer updateFundMainOrder(Map<String, Object> maps) {

        //主键
        ArrayList<String> keyIdList = (ArrayList<String>) maps.get("keyIds");
        String[] keyIds = null;
        if (keyIdList != null && keyIdList.size() > 0) {
            keyIds = new String[keyIdList.size()];
            for (int i = 0; i < keyIdList.size(); i++) {
                keyIds[i] = keyIdList.get(i);
            }
        }

        //其他查询条件 : 注意:不能和主键同时出现
        String gopayOrderId = (String) maps.get("gopayOrderId");

        //订单修改时间
        Date lastUpdTs = (Date) maps.get("lastUpdTs");

        //订单类型(20，认购；22.申购；24，赎回申请；)
        //String tranType = (String) maps.get("tranType");

        //订单状态：00，已申请；01，对账中；02，对账失败；03，对账成功；04, 交易成功；05，交易失败；06，交易关闭
        String orderType = (String) maps.get("orderType");

        //交易处理完成时间
        Date tranFinishTime = (Date) maps.get("tranFinishTime");

        //清算日期
        Date stlmDate = (Date) maps.get("stlmDate");

        //订单成交金额
        BigDecimal orderDealAmt = (BigDecimal) maps.get("orderDealAmt");

        //remaker2是在生成02018订单的时候为了关联之前的赎回分红退款订单,将02018的国付宝订单号放在了remaker2里
        String remaker2 = (String) maps.get("maker2");

        //02018订单总笔数
        String totalSum = (String) maps.get("orderRealFeeAmt");

        StringBuffer sql = new StringBuffer("");
        sql.append(" update FUND_GOPAY_CPS_GEN_ORDER p set ");
        Map<String, Object> param = new HashMap<String, Object>();
        if (maps.size() > 0) {
            if (lastUpdTs != null) {
                sql.append("  p.LAST_UPD_TS =:lastUpdTs ");
                param.put("lastUpdTs", lastUpdTs);
            }
            if (orderType != null) {
                sql.append(" , p.ORDER_TYPE =:orderType");
                param.put("orderType", orderType);
            }

            if (tranFinishTime != null) {
                sql.append(" , p.TRAN_FINISH_TIME =:tranFinishTime");
                param.put("tranFinishTime", tranFinishTime);
            }
            if (stlmDate != null) {
                sql.append(" , p.STLM_DATE =:stlmDate");
                param.put("stlmDate", stlmDate);
            }
            if (remaker2 != null) {
                sql.append(" , p.MER_REMARK2=:remaker2");
                param.put("remaker2", remaker2);
            }
            if (orderDealAmt != null) {
                sql.append(" , p.ORDER_DEAL_AMT =:orderDealAmt ");
                param.put("orderDealAmt", orderDealAmt);
            }
            if (totalSum != null) {
                sql.append(" , p.ORDER_REAL_FEE_AMT =:totalSum ");
                param.put("totalSum", totalSum);
            }


            if (keyIds != null && keyIds.length > 0) {
                sql.append(" where p.KEY_ID in (:keyIds ) ");
                param.put("keyIds", keyIds);
                return updateBySql(sql.toString(), param);
            }

            if (gopayOrderId != null) {
                sql.append(" where p.GOPAY_ORDER_ID=:gopayOrderId ");
                param.put("gopayOrderId", gopayOrderId);
                return updateBySql(sql.toString(), param);
            }

        }
        return null;
    }

    /**
     * 同上
     *
     * @param maps
     * @return
     */
    @Override
    public Integer updateMainOrder(Map<String, Object> maps) {

        //主键
        ArrayList<String> keyIdList = (ArrayList<String>) maps.get("keyIds");
        String[] keyIds = null;
        if (keyIdList != null && keyIdList.size() > 0) {
            keyIds = new String[keyIdList.size()];
            for (int i = 0; i < keyIdList.size(); i++) {
                keyIds[i] = keyIdList.get(i);
            }
        }
        //其他查询条件 : 注意:不能和主键同时出现
        String gopayOrderId = (String) maps.get("gopayOrderId");
        BigDecimal orderDealAmt = (BigDecimal) maps.get("orderDealAmt");
        Date tranFinishTime = (Date) maps.get("tranFinishTime");
        Date orderStlmTime = (Date) maps.get("orderStlmTime");
        Date lastUpdTs = (Date) maps.get("lastUpdTs");
        Integer txnStaCd = null;
        if (maps.get("txnStaCd") != null) {
            txnStaCd = Integer.parseInt(maps.get("txnStaCd").toString());
        }
        String remaker2 = (String) maps.get("maker2");
        String totalSum = (String) maps.get("orderRealFeeAmt");

        StringBuffer sql = new StringBuffer("");
        sql.append(" update CPS_GEN_MAIN_ORDER p set ");
        Map<String, Object> param = new HashMap<String, Object>();
        if (maps.size() > 0) {
            if (lastUpdTs != null) {
                sql.append(" p.LAST_UPD_TS =:lastUpdTs ");
                param.put("lastUpdTs", lastUpdTs);
            }
            if (orderDealAmt != null) {
                sql.append(" , p.ORDER_DEAL_AMT =:orderDealAmt ");
                param.put("orderDealAmt", orderDealAmt);
            }
            if (tranFinishTime != null) {
                sql.append(" , p.TRAN_FINISH_TIME =:tranFinishTime ");
                param.put("tranFinishTime", tranFinishTime);
            }
            if (orderStlmTime != null) {
                sql.append(" , p.ORDER_STLM_TIME =:stlmDate ");
                param.put("stlmDate", orderStlmTime);
            }
            if (remaker2 != null) {
                sql.append(" , p.REMARK2=:remaker2");
                param.put("remaker2", remaker2);
            }

            if (txnStaCd != null) {
                sql.append(", p.TXN_STA_CD =:txnStaCd ");
                param.put("txnStaCd", txnStaCd);
            }
            if (totalSum != null) {
                sql.append(" , p.ORDER_REAL_FEE_AMT =:totalSum ");
                param.put("totalSum", totalSum);
            }
            if (keyIds != null && (keyIds.length > 0)) {
                sql.append(" where p.GOPAY_ORDER_ID in (:keyIds ) ");
                param.put("keyIds", keyIds);
                return updateBySql(sql.toString(), param);
            }
            if (gopayOrderId != null) {
                sql.append(" where p.GOPAY_ORDER_ID=:gopayOrderId ");
                param.put("gopayOrderId", gopayOrderId);
                return updateBySql(sql.toString(), param);
            }
        }
        return null;
    }

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    @Override
    public Integer updateFundOrderCauseDiffer(Map<String, Object> maps, boolean flag) {
        //订单类型
        String[] tranTypes = (String[]) maps.get("tranType");
        //订单状态
        String orderType = (String) maps.get("orderType");
        //最后修改时间
        Date lastUpdTs = (Date) maps.get("lastUpdTs");
        String ordOrderType = (String) maps.get("ordOrderType");
        String gopayId = (String) maps.get("gopayId");
        Map<String, Object> map = new HashMap<>();
        StringBuffer sql = new StringBuffer("UPDATE FUND_GOPAY_CPS_GEN_ORDER set ");
        if (lastUpdTs != null) {
            sql.append(" LAST_UPD_TS=:lastUpdTs ");
            map.put("lastUpdTs", lastUpdTs);
        }
        if (orderType != null) {
            sql.append(" ,ORDER_TYPE=:orderType ");
            map.put("orderType", orderType);
        }

        if (ordOrderType != null) {
            sql.append(" WHERE ORDER_TYPE=:ordOrderType ");
            map.put("ordOrderType", ordOrderType);
        } else {
            return null;
        }
        if (flag) {
            if (gopayId != null) {
                sql.append(" AND MER_REMARK2=:gopayId ");
                map.put("gopayId", gopayId);
            }
        } else {
            if (gopayId != null) {
                sql.append(" AND GOPAY_ORDER_ID=:gopayId ");
                map.put("gopayId", gopayId);
            }
        }


        int i = updateBySql(sql.toString(), map);
        return i;
    }

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    @Override
    public Integer updateMainOrderCauseDiffer(Map<String, Object> maps, boolean flag) {
        //订单类型
        String[] orderTypes = (String[]) maps.get("ordOrderType");
        Date lastUpdTs = (Date) maps.get("lastUpdTs");
        //订单状态
        Integer txnStaCd = (Integer) maps.get("orderType");
        String gopayId = (String) maps.get("gopayId");
        Map<String, Object> map = new HashMap<>();
        StringBuffer sql = new StringBuffer("UPDATE CPS_GEN_MAIN_ORDER set ");
        if (lastUpdTs != null) {
            sql.append(" LAST_UPD_TS=:lastUpdTs ");
            map.put("lastUpdTs", lastUpdTs);
        }
        if (txnStaCd != null) {
            sql.append(" ,TXN_STA_CD=:txnStaCd ");
            map.put("txnStaCd", txnStaCd);
        }
        if (orderTypes != null) {
            sql.append(" WHERE ORDER_TYPE in (:orderTypes) ");
            map.put("orderTypes", orderTypes);
        } else {
            return null;
        }
        if (flag) {
            if (gopayId != null) {
                sql.append("AND REMARK2=:gopayId ");
                map.put("gopayId", gopayId);
            }
        } else {
            if (gopayId != null) {
                sql.append("AND GOPAY_ORDER_ID=:gopayId ");
                map.put("gopayId", gopayId);
            }
        }


        int i = updateBySql(sql.toString(), map);

        return i;

    }

    @Override
    public void updateFundOrderCauseDifferByOrders(Map<String, Object> map) {

        String[] order = (String[]) map.get("order");
        String[] tranType = (String[]) map.get("tranType");

        String orderType = (String) map.get("orderType");
        Date lastUpdTs = (Date) map.get("lastUpdTs");

        if (!"".equals(orderType) && !"".equals(lastUpdTs) && order.length > 0 && tranType.length > 0 && orderType != null && lastUpdTs != null) {
            StringBuffer sql = new StringBuffer("UPDATE FUND_GOPAY_CPS_GEN_ORDER set ORDER_TYPE=:orderType,LAST_UPD_TS=:lastUpdTs" +
                    "  WHERE GOPAY_ORDER_ID in (:orders) AND TRAN_TYPE in (:tranType)");

            Map<String, Object> map1 = new HashMap<>();
            map1.put("orderType", orderType);
            map1.put("lastUpdTs", lastUpdTs);
            map1.put("orders", order);
            map1.put("tranType", tranType);

            int i = updateBySql(sql.toString(), map1);
        }

    }

    @Override
    public void updateMainOrderCauseDifferByOrders(Map<String, Object> map) {
        String[] order = (String[]) map.get("order");
        String[] orderTyps = (String[]) map.get("tranType");

        String txnStaCd = (String) map.get("txnStaCd");
        Date lastUpdTs = (Date) map.get("lastUpdTs");

        if (order.length > 0 && orderTyps.length > 0 && txnStaCd != null && lastUpdTs != null && !"".equals(txnStaCd) && !"".equals(lastUpdTs)) {
            StringBuffer sql = new StringBuffer("UPDATE CPS_GEN_MAIN_ORDER set TXN_STA_CD=:txnStaCd,LAST_UPD_TS=:lastUpdTs" +
                    "  WHERE GOPAY_ORDER_ID in (:orders) AND ORDER_TYPE in (:tranType)");

            Map<String, Object> map1 = new HashMap<>();
            map1.put("txnStaCd", txnStaCd);
            map1.put("lastUpdTs", lastUpdTs);
            map1.put("orders", order);
            map1.put("tranType", orderTyps);

            int i = updateBySql(sql.toString(), map1);
        }
    }

    @Override
    public void batchInsertPayOrders(List<CpsGenPayOrder> cpsGenPayOrderList) {
        // TODO
    }

    @Override
    public void updateGoTransFundOrder(Map paraMap) {
        StringBuffer sb = new StringBuffer();

        if (paraMap != null) {
            sb.append(" update FundGopayCpsGenOrder t set t.totalOrderAmt = :merTxnAmt,t.merTxnAmt = :merTxnAmt,t.countNum = :countNum where 1=1 ");

            if (paraMap.get("merchantId") != null) {
                sb.append(" and t.merchantId = :merchantId");
            }
            if (paraMap.get("tranType") != null) {
                sb.append(" and t.tran_type in (:tranType)");
            }
            if (paraMap.get("stlmDate") != null) {
                sb.append(" and to_char(t.stlmDate,'yyyyMMdd') = :stlmDate");
            }
            if (paraMap.get("gopayIntTxnCd") != null) {
                sb.append(" and t.gopayIntTxnCd = :gopayIntTxnCd");
            }
            if (paraMap.get("tranType") != null) {
                sb.append(" and t.tranType = :tranType");
            }
            if (paraMap.get("orderType") != null) {
                sb.append(" and t.orderType = :orderType");
            }

        }
        updateByHql(sb.toString(), paraMap);
    }

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    @Override
    public void update00700AllOrder(Map<String, Object> map) {
        CpsGenMainOrder cpsGenMainOrder02012 = (CpsGenMainOrder) map.get("fundMainOrder02012");
        //update by wangdong 20170801 map中没有放入cpsGenMainOrder02018 在此注释
//        CpsGenMainOrder cpsGenMainOrder02018 = (CpsGenMainOrder) map.get("fundMainOrder02018");
        FundGopayCpsGenOrder fundGopayCpsGenOrder02012 = (FundGopayCpsGenOrder) map.get("fundGopayCpsGenOrder02012");
//        FundGopayCpsGenOrder fundGopayCpsGenOrder02018 = (FundGopayCpsGenOrder) map.get("fundGopayCpsGenOrder02018");
//        if(cpsGenMainOrder02018!=null && fundGopayCpsGenOrder02018!=null) {
//            update(fundGopayCpsGenOrder02018);
//            fundCpsMainDao.update(cpsGenMainOrder02018);
//        }else {
        update(fundGopayCpsGenOrder02012);
        fundCpsMainDao.update(cpsGenMainOrder02012);
//        }

    }

    @Override
    public void updateFundCpsMainOrderTypeByGopayOrderId(String gopayId, String orderType) {
        StringBuffer sb = new StringBuffer("UPDATE FundGopayCpsGenOrder set orderType=:orderType,LAST_UPD_TS=:lastUpdTs where gopayOrderId=:gopayOrderId");
        if (gopayId != null && orderType != null) {
            Map<String, Object> map = new HashMap<>();
            map.put("orderType", orderType);
            map.put("gopayOrderId", gopayId);
            map.put("lastUpdTs", new Date());
            updateByHql(sb.toString(), map);
        }
    }

    @Override
    public void updateFundCpsOrderStateByMermaker2(String merMaker2, String orderType) {
        StringBuffer sb = new StringBuffer("UPDATE FundGopayCpsGenOrder set orderType=:orderType where merRemark2=:merRemark2");
        if (merMaker2 != null && merMaker2 != null) {
            Map<String, Object> map = new HashMap<>();
            map.put("orderType", orderType);
            map.put("merRemark2", merMaker2);
            updateByHql(sb.toString(), map);
        }
    }

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    @Override
    public void updateMainOrderAndFundOrder(CpsGenMainOrder cpsGenMainOrder, FundGopayCpsGenOrder fundGopayCpsGenOrder) {
        update(fundGopayCpsGenOrder);
        fundCpsMainDao.update(cpsGenMainOrder);
    }

}